/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author WMThiet
 */
public class UtilCommon {
    public static Date ConvertToDate(String sDate){
        try{
            DateFormat utilDateFormatter = new SimpleDateFormat("dd/MM/yyyy");
            return utilDateFormatter.parse(sDate);
        }catch(Exception e){
            return new Date();
        }
    }
    
    public static Date ConvertToDate1(String sDate){
        try{
            DateFormat utilDateFormatter = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
            return utilDateFormatter.parse(sDate);
        }catch(Exception e){
            return new Date();
        }
    }
    
    public static String DateToString (Date date){
        DateFormat utilDateFormatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        return utilDateFormatter.format(date);
    }
    
    public static String DateToString1 (Date date){
        DateFormat utilDateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return utilDateFormatter.format(date);
    }
    
    public static int GetYear (Date date){
        DateFormat utilDateFormatter = new SimpleDateFormat("yyyy");
        return Integer.parseInt(utilDateFormatter.format(date));
    }
    
    public static String customFormat(String pattern, double value ) {
      DecimalFormat myFormatter = new DecimalFormat(pattern);
      String output = myFormatter.format(value);
      return output;
   }
}
